package elitech.vietnam.weatherfashion.dialog;

import java.io.File;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.v4.app.Fragment;
import android.view.View;
import android.widget.Button;
import elitech.vietnam.weatherfashion.MainActivity;
import elitech.vietnam.weatherfashion.NewPostActivity;
import elitech.vietnam.weatherfashion.R;

public class PicPickerDialog extends Dialog implements View.OnClickListener {
	
	private Fragment fragment;
	
	public PicPickerDialog(Context context, Fragment fragment) {
		super(context, R.style.Dialog);
		this.fragment = fragment;
	}
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.layout_dialogcamera);
		((Button) findViewById(R.id.dialogcamera_button_camera)).setOnClickListener(this);
		((Button) findViewById(R.id.dialogcamera_button_gallery)).setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		Intent intent = null;
		int req = 0;
		switch (v.getId()) {
		case R.id.dialogcamera_button_camera:
			intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
			intent.putExtra(android.provider.MediaStore.EXTRA_SCREEN_ORIENTATION, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
			intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(NewPostActivity.CAM_PATH)));
			req = MainActivity.REQ_CODE_CAM;
			break;
			
		case R.id.dialogcamera_button_gallery:
			intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
			req = MainActivity.REQ_CODE_LIB;
			break;

		default:
			break;
		}
		
		if (intent != null)
			fragment.startActivityForResult(intent, req);
		dismiss();
	}
}
